using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[CreateAssetMenu(fileName = "Effect19-给目标棋子的随机一个施加天命标记", menuName = "Skill/Effect/Effect19-给目标棋子的没有标记的一个最大攻击力的施加天命标记", order = 19)]
public class Effect19 : EffectBase
{
    public override void Apply(Pair pair, GameEvent e, List<Chess> targets)
    {
        if(targets == null || targets.Count == 0) return;
        var list = new List<Chess>();
        foreach (var target in targets)
        {
            if (!target.ChessDetail.PropheticMark)
            {
                if (list.Count == 0)
                {
                    list.Add(target);
                }
                else
                {
                    if (list[0].ChessDetail.Attack < target.ChessDetail.Attack)
                    {
                        list.Clear();
                        list.Add(target);
                    }
                    else if (list[0].ChessDetail.Attack == target.ChessDetail.Attack)
                    {
                        list.Add(target);
                    }
                }
            }
        }

        if (list.Count == 0)
        {
            return;
        }
       
        targets[Random.Range(0, list.Count)].ChessDetail.PropheticMark = true;
    }
}